package com.hotelvip.controller;

import com.hotelvip.common.utils.JSONResult;
import com.hotelvip.entity.ItemCat;
import com.hotelvip.service.ItemCatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品分类模块
 * @author Lzh
 * @date 2020/12/17 11:35
 */
@RestController
@RequestMapping("/item/itemCat")
@Api(basePath = "/item/itemCat",tags = "商品分类模块")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;

    @ApiOperation(value = "查询商品分类列表",httpMethod = "GET",notes = "parentId = 0  查询一级商品分类菜单")
    @GetMapping("/findItemCats/{parentId}")
    public JSONResult findItemCats(
            @ApiParam(value = "父级分类id",required = true) @PathVariable("parentId") Long parentId){
        return JSONResult.ok(itemCatService.findItemCats(parentId));
    }

    @ApiOperation(value = "按照id查询分类名称",httpMethod = "GET")
    @GetMapping("/findItemCatNameById")
    public JSONResult findItemCatNameById(Long itemCatId){
        return JSONResult.ok(itemCatService.findItemCatById(itemCatId));
    }

    @ApiOperation(value = "新增分类信息",httpMethod = "POST",notes = "填写name,parentId")
    @PostMapping("/saveItemCat")
    public JSONResult saveItemCat(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCat(itemCat);
        return JSONResult.ok();
    }


}
